package com.yonyou.crm.sys.quartz.ctrl;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.yonyou.crm.common.exception.CrmMessageException;
import com.yonyou.crm.common.rest.util.RequestUtil;
import com.yonyou.crm.common.rest.util.ResponseUtil;
import com.yonyou.crm.sys.quartz.rmitf.IDispatchGroupRmService;
import com.yonyou.crm.sys.quartz.ventity.DispatchGroupVO;

@RestController
@RequestMapping(value = "/quartz/taskgroups")
public class DispatchGroupCtrl {
	private final Logger logger = LoggerFactory.getLogger(getClass());


	@Autowired
	private IDispatchGroupRmService groupService;


	/**
	 * 查询任务列表
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws CrmMessageException
	 */
	@RequestMapping(method = RequestMethod.GET)
	public Object list(HttpServletRequest request, HttpServletResponse response)
			throws CrmMessageException {
		JSONObject rObj = new JSONObject();
		rObj.put("taskGroupList", groupService.selectDispatchGroupList());
		return ResponseUtil.getObject(rObj);
	}

	/**
	 * 新增任务分组
	 * 
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(method = RequestMethod.POST)
	public Object addTaskGroup(HttpServletRequest request,
			HttpServletResponse response) throws CrmMessageException {

		DispatchGroupVO taskGroupVO = RequestUtil.getVO(request,
				DispatchGroupVO.class);

		taskGroupVO = groupService.saveDispatchGroupVO(taskGroupVO);

		if (taskGroupVO.getId() == null) {
			throw new CrmMessageException("获取自增主键为空");
		}
		return ResponseUtil.getObject(taskGroupVO);
	}
}
